package com.service;

import java.util.List;

import com.dao.ProductsDAO;
import com.domain.Products;

public class ProductsService {
	public int insertProduct(Products product) {
		ProductsDAO dao = new ProductsDAO();
		return dao.insert(product);
	}

	public List<Products> getAllProduct() {
		ProductsDAO dao = new ProductsDAO();
		return dao.getAllProduct();
	}

	public Products getProductById(String code) {
		ProductsDAO dao = new ProductsDAO();
		return dao.getProductById(code);
	}

	public int deleteProductById(String code) {
		ProductsDAO dao = new ProductsDAO();
		Products product = getProductById(code);
		if (product != null) {
			dao.deleteProduct(product);
			return 1;
		}
		else {
			return 0;
		}
	}
}
